<?php
namespace app\configs\admin;

use app\admin\controller\Admin;
use think\Db;

use app\common\builder\ZBuilder; // 引入ZBuilder

class Resume extends Admin
{
    protected  $status=[
        0=>'未读',
        1=>'待定',
        2=>'不合适',
        3=>'待面试',
        4=>'待入职',
        5=>'待满岗',
        6=>'未满岗',
        10=>'满岗'];

    
    
   
    
	//简历投递列表
    public function index(){
        $list_tab = [
            'tab1' => ['title' => '简历管理', 'url' => url('index', ['group' => 'tab1'])],
            'tab2' => ['title' => '简历回收站', 'url' => url('index1', ['group' => 'tab2'])],
        ];
        $map = $this->getMap();
        $tag=$this->request->param("tag",null);
        if($tag==="0"){
            $map[]=['a.tag','=',0];
        }
        
        if($tag==="1"){
            $map[]=['a.tag','>',0];
        }
        
        
        $data_list = Db::name('zp_resume_job')
        ->alias("a")
        
        ->join("zp_resume b","a.resume_id=b.id")
        ->join("zp_job c","a.job_id=c.id")
        ->join("user d","b.user_id=d.id")
        ->where($map)
        ->where("a.status",1)
        ->field("a.id aid,a.create_time acreate_time,a.status astatus,a.tag,a.remaks,b.*,c.id job_id,c.title,c.company,c.point,c.point_tj,c.point_time,d.idcard")
        ->order("a.id desc")
        ->paginate();

        // 分页数据
        $page = $data_list->render();
        $category=Db::name('zp_category')->column("id,name");
        
        $btn_del = [
            'title' => '删除',
            'icon'  => 'fa fa-fw fa-remove',
            'class' => 'btn btn-xs btn-default ajax-get confirm',
            'href'  => url('del', ['id' => '__aid__'])
        ];
        
        $btn_edit = [
            'title' => '最终积分',
            'icon'  => 'fa fa-fw fa-heart',
            'href'  => url('point_set', ['id' => '__job_id__'])
        ];
        
//         $btn_resume = [
//             'title' => '简历投递情况',
//             'icon'  => 'fa fa-fw fa-th',
//             'href'  => url('resume_list', ['id' => '__id__'])
//         ];
        
        $btn_excel_view = [
            'title' => '导出会员简历',
            'icon'  => 'fa fa-fw fa-check',
            'class' => 'btn btn-primary js-get js-blank',
            'href'  => url('excel_out_sign')
        ];
        
        
        
        $all=Db::name('zp_resume_job')->where("status",1)->count("id");
        $sta1=Db::name('zp_resume_job')->where("tag",0)->where("status",1)->count("id");
        $stahot=Db::name('zp_resume_job')->where("tag",">",1)->where("status",1)->count("id");
        
        $btn_all = [
            'title' => '全部:'.$all."条",
            'href'  =>  url('index')
        ];
        
        $btn_sta1 = [
            'title' => '未读'.$sta1."条",
            'href'  => url('index',['tag'=>0])
        ];
        
        
        $btn_stahot = [
            'title' => '已读'.$stahot."条",
            'href'  => url('index',['tag'=>1])
        ];
        
        
        
        
        $css = <<<EOF
           <style>
                .table-builder > tbody > tr > td{white-space: normal;}
           </style>
EOF;
        $js = <<<EOF
            <script type="text/javascript">
                $(document).ready(function(){
                    $(".select-edit").on("click",function(){
                        alert('请确认是否要修改简历状态，满岗会导致积分赠送请谨慎操作');
});


                });
            </script>
EOF;
        //		dump($data_list);die;
        //$zp_category=Db::name("zp_category")->column("id,name");
        return ZBuilder::make('table')
        ->setPageTitle('简历列表')
        ->setTableName('zp_resume_job') // 指定数据表名
        ->setPrimaryKey('aid')	//设置主键
        ->addFilterList('tag',$this->status) // 添加筛选
        ->addFilterList('sex',['保密','男','女']) // 添加筛选
        ->setPageTips('<span style="color:red;">简历状态标记选择‘满岗’会有产生积分赠送，请谨慎操作</span>')
       // ->hideCheckbox()
        ->setSearch(['b.user_name' => '姓名','b.sex' => '性别','b.phone' => '电话','c.company' => '投递单位','b.qiw_dd' => '期望地点','b.qiw_xz' => '期望薪资','b.qiw_zw' => '期望职位']) // 设置搜索参数
        ->addColumns([ // 批量添加列
            ['user_name', '姓名'],
            ['sex', '性别',['保密','男','女']],
            ['birthday', '生日'],
            ['phone', '电话'],
            ['minzu', '民族'],
            ['idcard', '身份证'],
            ['qiw_zw', '期望职位'],
            ['qiw_dd', '期望地点'],
            ['qiw_xz', '期望薪资'],
           
           
            ['point', '最终积分'],
//             ['point_tj', '领取条件'],
//             ['point_time', '送达时间'],
            ['company', '投递单位'],
            ['acreate_time', '投递时间'],
            ['tag', '标记','select',$this->status],
            ['remaks', '备注','text.edit'],
            //['astatus|status', '作废','switch'],
           // ['content', '文字内容','popover'],
        ])
        ->addColumn('right_button', '操作', 'btn')
//         ->addRightButton('btn_resume',$btn_resume,1) // 批量添加右侧按钮1
        ->addRightButton('btn_del',$btn_del) // 批量添加右侧按钮1
        ->addRightButton('btn_edit',$btn_edit,1) // 批量添加右侧按钮1
        ->addTopButton('delete') // 批量添加右侧按钮1
        ->addTopButton('btn_excel_view',$btn_excel_view) 
        ->addTopButton('btn_all',$btn_all) // 批量添加右侧按钮1
        ->addTopButton('sta1',$btn_sta1) // 批量添加右侧按钮1
        ->addTopButton('stahot',$btn_stahot) // 批量添加右侧按钮1
        ->setRowList($data_list) // 设置表格数据
        ->setPages($page) // 设置分页数据
        ->setExtraCss($css)
        ->setExtraJs($js)
        ->setTabNav($list_tab,  'tab1')
        ->fetch();
    }
	
    
    //简历投递列表
    public function index1(){
        $list_tab = [
            'tab1' => ['title' => '简历管理', 'url' => url('index', ['group' => 'tab1'])],
            'tab2' => ['title' => '简历回收站', 'url' => url('index1', ['group' => 'tab2'])],
        ];
        $map = $this->getMap();
        
        $data_list = Db::name('zp_resume_job')
        ->alias("a")
        
        ->join("zp_resume b","a.resume_id=b.id")
        ->join("zp_job c","a.job_id=c.id")
        ->join("user d","b.user_id=d.id")
        ->where($map)
        ->where("a.status",0)
        ->field("a.id aid,a.create_time acreate_time,a.status astatus,a.tag,b.*,c.title,c.id job_id,c.company,c.point,d.idcard")
        ->order("a.id desc")
        ->paginate();
        
        // 分页数据
        $page = $data_list->render();
        $category=Db::name('zp_category')->column("id,name");
        
        $btn_del = [
            'title' => '恢复',
            'icon'  => 'fa fa-fw fa-check',
            'class' => 'btn btn-xs btn-default ajax-get confirm',
            'href'  => url('re', ['id' => '__aid__'])
        ];
        
        $btn_edit = [
            'title' => '最终积分',
            'icon'  => 'fa fa-fw fa-heart',
            'href'  => url('point_set', ['id' => '__job_id__'])
        ];

        
        $btn_excel_view = [
            'title' => '导出会员简历',
            'icon'  => 'fa fa-fw fa-check',
            'class' => 'btn btn-primary js-get js-blank',
            'href'  => url('excel_out_sign')
        ];
        
        $css = <<<EOF
           <style>
                .table-builder > tbody > tr > td{white-space: normal;}
           </style>
EOF;
        //		dump($data_list);die;
        //$zp_category=Db::name("zp_category")->column("id,name");
        return ZBuilder::make('table')
        ->setPageTitle('简历列表')
        ->setTableName('zp_resume_job') // 指定数据表名
        ->setPrimaryKey('aid')	//设置主键
        //->addFilter(['tag'],['未读','可面试','待定','不合适','暂未接通']) // 添加筛选
        // ->hideCheckbox()
        ->setSearch(['b.user_name' => '姓名','b.phone' => '电话','b.qiw_dd' => '期望地点','b.qiw_xz' => '期望薪资','b.qiw_zw' => '期望职位']) // 设置搜索参数
        ->addColumns([ // 批量添加列
            ['user_name', '姓名'],
            ['sex', '性别',['保密','男','女']],
            ['birthday', '生日'],
            ['phone', '电话'],
            ['minzu', '民族'],
            ['idcard', '身份证'],
            ['qiw_zw', '期望职位'],
            ['qiw_dd', '期望地点'],
            ['qiw_xz', '期望薪资'],
            
            
            ['point', '最终积分'],
            ['dw', '投递单位','callback',function($data){
                $a=Db::name("zp_resume_job")
                ->alias("a")
                ->join("zp_job b","a.job_id=b.id")
                ->where("a.resume_id",$data['id'])
                ->order("a.id desc")
                ->value("company");
                return $a;
            }, '__data__'],
            ['acreate_time', '投递时间'],
            ['tag', '标记/状态',$this->status],
            ])
            ->addColumn('right_button', '操作', 'btn')
            //         ->addRightButton('btn_resume',$btn_resume,1) // 批量添加右侧按钮1
        ->addRightButton('btn_del',$btn_del) // 批量添加右侧按钮1
        //->addRightButton('btn_edit',$btn_edit,1) // 批量添加右侧按钮1
        ->addRightButton('delete') // 批量添加右侧按钮1
        ->addTopButton('delete') // 批量添加右侧按钮1
        ->addTopButton('btn_excel_view',$btn_excel_view)
        ->setRowList($data_list) // 设置表格数据
        ->setPages($page) // 设置分页数据
        ->setExtraCss($css)
        ->setTabNav($list_tab,  'tab2')
        ->fetch();
    }
    
    public function del($id){
        $r=Db::name("zp_resume_job")->where("id",$id)->update([
            "status"=>0
        ]);
        return $this->success('删除成功');
    }
    public function re($id){
        $r=Db::name("zp_resume_job")->where("id",$id)->update([
            "status"=>1
        ]);
        return $this->success('恢复成功');
    }

    //最终积分 
    public function point_set($id){
        if ($this->request->isPost()) {
            $data = $this->request->post();
            
            $data['update_time']=date("Y-m-d H:i:s");
            if(!$data['point']){
                return $this->error('请设置积分');
            }
            
           

            $r=db('zp_job')->where("id",$id)->update($data);
            if($r){
                return $this->success('设置成功',url("index"), '_parent_reload');
            }else {
                return $this->error('设置失败',url("index"), '_parent_reload');
            }
        }
        
        $info=Db::name("zp_job")->find($id);
        
        // 使用ZBuilder快速创建表单
        return ZBuilder::make('form')
        ->setPageTitle('新增') // 设置页面标题
        ->addFormItems([ // 批量添加表单项
            ['text', 'point', '最终积分'],
            ['text', 'point_tj', '领取条件'],
            ['text', 'point_time', '送达时间'],
        ])
        ->setFormData($info) // 设置表单数据
        //->isAjax(false)
        ->fetch();
    }
    
    
    public function excel_out_sign(){
        action_log('导出简历', 'configs', "1", UID, session('user_auth')['nickname']."导出简历");
        $ids=input('get.ids/a');
        if( !isset($ids[0])||empty($ids['0'])){
            $this->error("请选择简历");
        }
        
        $data_list = Db::name('zp_resume_job')
        ->alias("a")
        
        ->join("zp_resume b","a.resume_id=b.id")
        ->join("zp_job c","a.job_id=c.id")
        ->join("user d","b.user_id=d.id")
        ->where("a.id","in",$ids[0])
        ->field("a.id aid,a.create_time acreate_time,a.tag,b.*,if(b.sex=1,'男','女') as sex,c.title,c.company,d.point,d.idcard")
        ->order("a.id desc")->select();
        
//         $data_list = Db::name('zp_resume')
//         ->alias("a")
//         ->join("user b","a.user_id=b.id")
//         ->where("a.id","in",$ids[0])
//         ->field("a.*,if(a.sex=1,'男','女') as sex,b.username,b.nickname,b.idcard,b.avatar,b.gender,b.birthday,b.createtime ucreatetime,b.point,b.nation,b.education")
//         ->order("a.id desc")
//         ->select();
        
        //exit;
        // 设置表头信息（对应字段名,宽度，显示表头名称）
        $cellName = [
            ['user_name', '30','姓名'],
            ['sex', '12','性别'],
            ['birthday', '25','生日'],
            ['phone', '16','电话'],
            ['minzu', '8','民族'],
            ['point', '8','积分'],
            ['qiw_dd', '20','期望地点'],
            ['qiw_xz', '10','期望薪资'],
            ['qiw_zw', '15','期望职位'],
            ['company', '15','投递单位'],
            ['acreate_time', '15','投递时间'],
        ];
        
        plugin_action('Excel/Excel/export', ['简历投递数据'.date('Y-m-d H:i:s'), $cellName, $data_list]);
    }
    
    public function job_add(){
        if ($this->request->isPost()) {
            $data = $this->request->post();
            
            $data['create_time']=date("Y-m-d H:i:s");
            if(!$data['region_id']){
                return $this->error('请选择地区');
            }
            
            if(!isset($data['category'])){
                return $this->error('请选择工种和分类');
            }
            $data['category']=implode(",",$data['category']);
            $region_pid=Db::name("zp_area")->find($data['region_id']);
            $city_pid=Db::name("zp_area")->where("id",$region_pid['pid'])->value("pid");
            $data['city_id']=$region_pid['pid'];
            $data['province_id']=$city_pid;
            
            $data['lat']=$region_pid['lat'];
            $data['lng']=$region_pid['lng'];
            $r=db('zp_job')->insert($data);
            if($r){
                return $this->success('添加成功',url("index"));
            }else {
                return $this->error('添加失败',url("index"));
            }
        }
        //$list_province=Db::name("zp_area")->where("pid",100000)->column("name","id");
        $category=Db::name("zp_category")->where("pid",0)->column("id,name");
       
        //halt($list_province);
        // 使用ZBuilder快速创建表单
        return ZBuilder::make('form')
        ->setPageTitle('新增') // 设置页面标题
        ->addFormItems([ // 批量添加表单项
            ['text', 'title', '简历标题', ''],
            
           //['linkages', 'category', '所属分类','','zp_category',2],
           // ['checkbox', 'category', '所属分类','',$category],
            ['linkage', 'category1', '选择分类','',$category,'',url('get_cate'), 'category', 'category'],
            ['select', 'category', '选择工种', '','','', 'multiple'],
            ['image', 'cover', '封面图'],
            ['tags', 'tags', '福利标签','多标签请按回车键，如：五险一金,双休'],
            ['text', 'company', '公司名称'],
            ['text', 'money', '待遇'],
            ['text', 'contact', '联系人'],
            ['text', 'phone', '联系电话'],
            ['number', 'point', '推广积分'],
            //['number', 'point2', '入职积分'],
            
            
            
//             ['linkage', 'province_id', '选择省份','',$list_province,'510000',url('get_city'), 'city_id,region_id', 'province'],
//             ['linkage', 'city_id', '选择城市', '', '', '', url('get_area'), 'region_id'],
            ['linkages', 'region_id', '选择所在地区', '', 'zp_area', 4,510105],
            ['text', 'address', '详细地址'],
            ['text', 'info_from', '公司介绍'],
           // ['bmap','bmap','地图','lDneqLvRX2mnQloI1KhkjYXi', '', '104.234923,30.529877'],
            ['wangeditor', 'content', '简历详情'],
           
        ])
        ->layout([
            "title"=>3,
            "category"=>6,
            "cover"=>3,
            
//             "province_id"=>3,
//             "city_id"=>3,
            "region_id"=>9,
            "address"=>3,
            
            "money"=>3,
            "contact"=>3,
            "phone"=>3,
            "company"=>3,
            "point"=>3,
            "point2"=>3,
            "category1"=>3,
            "category"=>3,
        ])
        //->isAjax(false)
        ->fetch();
    }
    public function get_cate($category)
    {
        $arr['code'] = '1'; //判断状态
        $arr['msg'] = '请求成功'; //回传信息
        $list=Db::name("zp_category")->where("pid",$category)->column("name","id");; //数据
        $ls=[];
        foreach ($list as $k=>$v){
            $ls[$k]['key']=$k;
            $ls[$k]['value']=$v;
        }
        $arr['list'] =$ls;
        return json($arr);
    }
    
    // 根据省份获取城市
    public function get_city($province = 510000)
    {
        $arr['code'] = '1'; //判断状态
        $arr['msg'] = '请求成功'; //回传信息
         $list=Db::name("zp_area")->where("pid",$province)->column("name","id");; //数据
         $ls=[];
         foreach ($list as $k=>$v){
             $ls[$k]['key']=$k;
             $ls[$k]['value']=$v;
         }
         $arr['list'] =$ls;
        return json($arr);
    }
    
    public function get_area($city_id = '')
    {
        $arr['code'] = '1'; //判断状态
        $arr['msg'] = '请求成功'; //回传信息
        $list=Db::name("zp_area")->where("pid",$city_id)->column("name","id");; //数据
        $ls=[];
        foreach ($list as $k=>$v){
            $ls[$k]['key']=$k;
            $ls[$k]['value']=$v;
        }
        $arr['list'] =$ls;
        return json($arr);
    }
    
    public function job_edit($id=null){
        if ($id === null) $this->error('缺少参数');
        $info = db('zp_job')->find($id);
        if ($this->request->isPost()) {
            $data = $this->request->post();
            if(!$data['region_id']){
                return $this->error('请选择地区');
            }
            
            if(!isset($data['category'])){
                return $this->error('请选择工种和分类');
            }
            $data['category']=implode(",",$data['category']);
            
            $region_pid=Db::name("zp_area")->find($data['region_id']);
            $city_pid=Db::name("zp_area")->where("id",$region_pid['pid'])->value("pid");
            $data['city_id']=$region_pid['pid'];
            $data['province_id']=$city_pid;

            $data['lat']=$region_pid['lat'];
            $data['lng']=$region_pid['lng'];
            
            $data['update_time']=date("Y-m-d H:i:s");
            $r=db('zp_job')->where("id",$id)->update($data);
            if($r){
                return $this->success('修改成功',url('index'));
            }else {
                return $this->error('修改失败',url('index'));
            }
        }
       // $list_province=Db::name("zp_area")->where("pid",100000)->column("name","id");
        $category=Db::name("zp_category")->where("pid",0)->column("id,name");
        return ZBuilder::make('form')
        ->setPageTitle('编辑') // 设置页面标题
        ->addFormItems([ // 批量添加表单项
            ['hidden', 'id'],
            ['text', 'title', '简历标题', ''],
            
           // ['linkages', 'category', '所属分类','','zp_category',2],
            ['linkage', 'category1', '选择分类','',$category,'',url('get_cate'), 'category', 'category'],
            ['select', 'category', '选择工种', '',$category,'', 'multiple'],
            ['image', 'cover', '封面图'],
            ['tags', 'tags', '福利标签','多标签请按回车键，如：五险一金,双休'],
            ['text', 'company', '公司名称'],
            ['text', 'money', '待遇'],
            ['text', 'contact', '联系人'],
            ['text', 'phone', '联系电话'],
            ['number', 'point', '推广积分'],
            //['number', 'point2', '入职积分'],
            
            //             ['linkage', 'province_id', '选择省份','',$list_province,'510000',url('get_city'), 'city_id,region_id', 'province'],
        //             ['linkage', 'city_id', '选择城市', '', '', '', url('get_area'), 'region_id'],
            ['linkages', 'region_id', '选择所在地区', '', 'zp_area', 4],
            ['text', 'address', '详细地址'],
            ['text', 'info_from', '公司介绍'],
            ['wangeditor', 'content', '简历详情'],
            
        ])
        ->layout([
            "title"=>3,
            "category"=>6,
            "cover"=>3,
            
            "province_id"=>3,
            "city_id"=>3,
            "region_id"=>9,
            "address"=>3,
            
            "money"=>3,
            "contact"=>3,
            "phone"=>3,
            "company"=>3,
            "point"=>3,
            "point2"=>3,
            "category1"=>3,
            "category"=>3,
        ])->setFormData($info) // 设置表单数据
        //->isAjax(false)
        ->fetch();
        
    }
    
    
    public function resume_list($id){
        $map = $this->getMap();
        $map[]=['a.job_id','=',$id];
        $data_list = Db::name('zp_resume_job')
        ->alias("a")
        ->join("zp_resume b","a.resume_id=b.id")
        ->where($map)
        ->field("a.id aid,a.status astatus,a.create_time acreate_time,b.*")
        ->order("aid desc")
        ->paginate();
        // 分页数据
        $page = $data_list->render();

        $btn_add = [
            'title' => '稳岗奖励',
            'icon'  => 'fa fa-fw fa-heart',
            'class' => 'btn btn-xs btn-default ajax-get confirm',
            'data-title' => '确定要稳岗操作吗？操作后不可撤销',
            'href'  => url('resume_job', ['id' => '__aid__','job_id' => $id,'user_id' => '__user_id__'])
        ];
        
        $css = <<<EOF
           <style>
                .table-builder > tbody > tr > td{white-space: normal;}
           </style>
EOF;
        //		dump($data_list);die;
        $zp_category=Db::name("zp_category")->column("id,name");
        return ZBuilder::make('table')
        ->setPageTitle('投递列表')
        ->setTableName('zp_resume_job') // 指定数据表名
        ->setPrimaryKey('aid')	//设置主键
        ->hideCheckbox()
        ->setSearch(['b.user_name' => '姓名','b.phone' => '电话']) // 设置搜索参数
        ->addColumns([ // 批量添加列
            ['user_name', '姓名'],
            ['sex', '性别',['0'=>'保密','1'=>'男','2'=>'女']],
            ['birthday', '出生年月'],
            ['phone', '电话'],
            ['minzu', '民族'],
            ['qiw_dd', '期望地点'],
            ['qiw_xz', '期望薪资'],
            ['qiw_zw', '期望职位'],
            ['acreate_time', '投递时间'],
            ['astatus', '是否稳岗',["否","否","否","否","是"]],
            // ['content', '文字内容','popover'],
            ])
            ->addColumn('right_button', '操作', 'btn')
            ->addRightButton('btn_add',$btn_add) // 批量添加右侧按钮1
            ->addRightButton('delete') // 批量添加右侧按钮1
            
            ->setRowList($data_list) // 设置表格数据
            ->setPages($page) // 设置分页数据
            ->setExtraCss($css)
            ->fetch();
    }
    
    
    public function user_message($id,$content=''){
        $r=Db::name('user_message')->insert([
            "content"=>$content,
            "user_id"=>$id,
            "create_time"=>date("Y-m-d H:i:s"),
        ]);
        return $r;
    }
    
    
    public function resume_job($id,$job_id,$user_id,$flag=0){
        $status=Db::name("zp_resume_job")->where("id",$id)->value("status");
        if($status==10){
           return $this->error("已稳岗,无需再次操作");
        }
        $time=date("Y-m-d H:i:s");
        $r=Db::name("zp_resume_job")->where("id",$id)->update([
            "status"=>10,
            "update_time"=>$time,
        ]);
        
        //计算推荐人积分
        $point=Db::name("zp_job")->where("id",$job_id)->value("point");
        if(!$point){
            if($r){
                return $this->success("设置成功");
            }else{
                return $this->error("设置失败");
            }
        }
        $user=Db::name("user")->find($user_id);
        //稳岗奖励给自己
        $wengang=Db::name("admin_config")->where("id",43)->value("value"); //比例
        //写入积分纪录并计算积分
        $wengang=$point*$wengang/100;
        $insert_datawengang=[
            "user_id"=>$user_id,
            "point"=>(int)$wengang,
            "create_time"=>$time,
            "remarks"=>"稳岗奖励，".$user['username']."稳岗成功",
        ];
        Db::name("point_log")->insert($insert_datawengang);
        Db::name("user")->where("id",$user_id)->setInc('point',(int)$wengang);
        
        $status1=Db::name("zp_resume_job")->where("id",$id)->value("status");

        $message="您的简历已被修改为：".$this->status[$status1];
        $this->user_message($user_id,$message);
        
        //查找一级分销人
        $recommend1=Db::name("user")->where("id",$user_id)->value("recommend_id");
        
        if($recommend1){
            $one=Db::name("admin_config")->where("id",40)->value("value"); //比例
            
            //写入积分纪录并计算积分
            $point1=$point*$one/100;
            $insert_data1=[
                "user_id"=>$recommend1,
                "point"=>(int)$point1,
                "create_time"=>$time,
                "remarks"=>"一级分销奖励，".$user['username']."稳岗成功",
            ];
            Db::name("point_log")->insert($insert_data1);
            Db::name("user")->where("id",$recommend1)->setInc('point',(int)$point1);
            
            
            $message=$user['username']."的简历已被修改为：".$this->status[$status1];
            $this->user_message($recommend1,$message);
        }
        
        //查找一级二级比例 
        $recommend2=Db::name("user")->where("id",$recommend1)->value("recommend_id");
        if($recommend2){
            $two=Db::name("admin_config")->where("id",41)->value("value");
            
            //写入积分纪录并计算积分
            $point2=$point*$two/100;
            $insert_data2=[
                "user_id"=>$recommend2,
                "point"=>(int)$point2,
                "create_time"=>$time,
                "remarks"=>"二级分销奖励，".$user['username']."稳岗成功",
            ];
            Db::name("point_log")->insert($insert_data2);
            Db::name("user")->where("id",$recommend2)->setInc('point',(int)$point2);
            $message=$user['username']."的简历已被修改为：".$this->status[$status1];
            $this->user_message($recommend2,$message);
        }
        if($flag){
            return true;
        }
        if($r){
            return $this->success("设置成功");
        }else{
            return $this->error("设置失败");
        }
        
        
    }
    
    
    public function quickEdit($record = [])
    {
        $field           = input('post.name', '');
        $value           = input('post.value', '');
        $type            = input('post.type', '');
        $id              = input('post.pk', '');
        $validate        = input('post.validate', '');
        $validate_fields = input('post.validate_fields', '');
        $field == '' && $this->error('缺少字段名');
        $id    == '' && $this->error('缺少主键值');
        $info=Db::name("zp_resume_job")->where("id",$id)->find();
        $job_id=$info['job_id'];
        $user_id=Db::name("zp_resume")->where("id",$info['resume_id'])->value("user_id");
        $user=Db::name("user")->find($user_id);
        
        
        if($field=="tag"){
            if($value==10){ //满岗需要分销积分比例
                
                if($job_id && $user_id){
                    $this->resume_job($id,$job_id,$user_id,1);
                }
                
            }else {
                $message="您的简历已被修改为：".$this->status[$value];
                $this->user_message($user_id,$message);
                
                
                
                $recommend1=Db::name("user")->where("id",$user_id)->value("recommend_id");
                
                if($recommend1){
                    $message=$user['username']."的简历已被修改为：".$this->status[$value];
                    $this->user_message($recommend1,$message);
                }
                
                //查找一级二级比例
                $recommend2=Db::name("user")->where("id",$recommend1)->value("recommend_id");
                if($recommend2){
                    $message=$user['username']."的简历已被修改为：".$this->status[$value];
                    $this->user_message($recommend2,$message);
                }
                
                
            }
        }
        
        
        $Model = $this->getCurrModel();
        $protect_table = [
            '__ADMIN_USER__',
            '__ADMIN_ROLE__',
            config('database.prefix').'admin_user',
            config('database.prefix').'admin_role',
        ];
        
        // 验证是否操作管理员
        if (in_array($Model->getTable(), $protect_table) && $id == 1) {
            $this->error('禁止操作超级管理员');
        }
        
        // 验证器
        if ($validate != '') {
            $validate_fields = array_flip(explode(',', $validate_fields));
            if (isset($validate_fields[$field])) {
                $result = $this->validate([$field => $value], $validate.'.'.$field);
                if (true !== $result) $this->error($result);
            }
        }
        
        switch ($type) {
            // 日期时间需要转为时间戳
            case 'combodate':
                $value = strtotime($value);
                break;
                // 开关
            case 'switch':
                $value = $value == 'true' ? 1 : 0;
                break;
                // 开关
            case 'password':
                $value = Hash::make((string)$value);
                break;
        }
        
        // 主键名
        $pk     = $Model->getPk();
        $result = $Model->where($pk, $id)->setField($field, $value);
        
        cache('hook_plugins', null);
        cache('system_config', null);
        cache('access_menus', null);
        if (false !== $result) {
            // 记录行为日志
            if (!empty($record)) {
                call_user_func_array('action_log', $record);
            }
            $this->success('操作成功');
        } else {
            $this->error('操作失败');
        }
    }
    
    
    
   
}
?>